﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ListCategories
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript" language="javascript">

        function EditCategory(Id) {
            window.location = "../../UserAdministration/Category/Edit?Id=" + Id;
        }

        function DisableCategory(Id) {
            $(document).ready(function () {
                $.ajax({
                    url: '<%= ResolveUrl("~/UserAdministration/Category/DisableCategory?Id=") %>' + Id,
                    type: 'POST',
                    dataType: 'json',
                    data: '{}',
                    contentType: 'application/json; charset=utf-8',
                    success: function (data) {
                        if (data.Check == "0") {
                            $("#lblResponse").show();
                            $("#lblResponse").html("Failed, contact your site Admin");
                            $("#lblResponse").removeClass("success").addClass("error");
                            return;
                        }
                        if (data.Check == "1") {
                            $("#lblResponse").show();
                            $("#lblResponse").html(data.Message);
                            $("#lblResponse").removeClass("error").addClass("success");
                            return;
                        }
                    }
                });
            });
        }

        function DeleteCategory(Id) {
            $(document).ready(function () {

                $.ajax({
                    url: '<%= ResolveUrl("~/UserAdministration/Category/DeleteCategory?Id=") %>' + Id,
                    type: 'POST',
                    dataType: 'json',
                    data: '{}',
                    contentType: 'application/json; charset=utf-8',
                    success: function (data) {
                        if (data.Check == "0") {
                            $("#lblResponse").show();
                            $("#lblResponse").html("Failed, contact your site Admin");
                            $("#lblResponse").removeClass("success").addClass("error");
                            return;
                        }
                        if (data.Check == "1") {
                            $("#lblResponse").show();
                            $("#lblResponse").html(data.Message);
                            $("#lblResponse").removeClass("error").addClass("success");
                            document.getElementById(Id).style.display = 'none';
                            return;
                        }
                    }
                });

            });
        }

        
    </script>


    <h2 style="width: 200px;height:20px">List Categories</h2>
    <div style="width:200px;"><div id="lblResponse" style="display: none;"></div></div>

    <table id="CategoryList">
        <thead>
            <tr>  
                <th style="width:200px;text-align:center;">Name</th>
                <th style="width:200px;text-align:center;">Years</th>
                <th style="width:16%;text-align:center;">Edit</th>
                <th style="width:16%;text-align:center;">Active</th>
                <th style="width:16%;text-align:center;">Delete</th>
            </tr>
        </thead>
        <tbody>
            <% foreach (var category in Model.Category)
               { %>
            <tr id="<%= Html.Encode(category.Id) %>">
                <td><%= Html.Encode(category.Name) %></td>
                <td><%= Html.Encode(category.Year) %></td>
                <td style="text-align:center;"><a href="#" onclick="javascript:EditCategory('<%=Html.Encode(category.Id) %>');return false;"">Edit</a></td>
                <td style="text-align:center;"><a href="#" onclick="javascript:DisableCategory('<%=Html.Encode(category.Id) %>');return false;"">Disable</a></td>
                <td style="text-align:center;"><a href="#" onclick="javascript:DeleteCategory('<%=Html.Encode(category.Id) %>');return false;"">Delete</a></td>
            </tr>
            <% } %>
        </tbody>
    </table>

</asp:Content>
